package com.qh.resourcehub.program.audit.controller;

import com.qh.resourcehub.program.audit.service.SourceCodeAuditExamineService;
import com.qh.resourcehub.program.dto.SourceCodeAuditDto;
import com.qh.resourcehub.program.vo.SourceCodeAuditVo;
import com.qh.resourcehub.utils.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
//青海省气象部门信息系统源代码安全评估审计报告（数据服务室）
@RestController
@RequestMapping("/sourceCodeAuditExamine")
public class SourceCodeAuditExamineController {
    @Autowired
    private SourceCodeAuditExamineService sourceCodeAuditService;
    /*
     * @Description:
     * @param 查询审核信息
     * @return
     * @Author: Y6
     * @Date: 2025/4/18 14:19
     */
    @PostMapping("/querySourceCodeAuditExamineData")
    public ApiResponse querySourceCodeAuditExamineData(@RequestBody SourceCodeAuditDto sourceCodeAuditDto) {
        try {
            List<SourceCodeAuditVo> data = sourceCodeAuditService.querySourceCodeAuditExamineData(sourceCodeAuditDto);
            if (data.size()>0){
                return ApiResponse.succeed(data);
            }else {
                return ApiResponse.succeedNoData();
            }
        }catch (Exception e){
            e.printStackTrace(); // 打印完整堆栈信息
            return ApiResponse.succeedRequestErr("查询失败: " + e.getMessage()); // 返回详细错误信息
        }
    }

    /**examine
     * 源代码安全评估审计报告通过
     * @param
     * @return
     */
    @PostMapping("/ApplicationPass")
    public ApiResponse ApplicationPass(@RequestBody SourceCodeAuditDto sourceCodeAuditDto) {
        try {
            int i = sourceCodeAuditService.ApplicationPass(sourceCodeAuditDto);
            if (i>0){
                return ApiResponse.succeedRequest();
            }else {
                return ApiResponse.succeedRequestNo();
            }
        }catch (Exception e){
            e.printStackTrace(); // 打印完整堆栈信息
            return ApiResponse.succeedRequestErr("操作失败: " + e.getMessage()); // 返回详细错误信息
        }
    }
    /**examine
     * 源代码安全评估审计报告驳回
     * @param
     * @return
     */
    @PostMapping("/ApplicationReject")
    public ApiResponse ApplicationReject(@RequestBody SourceCodeAuditDto sourceCodeAuditDto) {
        try {
            int i = sourceCodeAuditService.ApplicationReject(sourceCodeAuditDto);
            if (i>0){
                return ApiResponse.succeedRequest();
            }else {
                return ApiResponse.succeedRequestNo();
            }
        }catch (Exception e){
            e.printStackTrace(); // 打印完整堆栈信息
            return ApiResponse.succeedRequestErr("操作失败: " + e.getMessage()); // 返回详细错误信息
        }
    }
}